import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ShoppingCartInterface extends JFrame {
    public ShoppingCartInterface() {
        setTitle("二手交易平台 - 购物车");
        setSize(400, 700);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        
        // 主面板
        JPanel mainPanel = new JPanel();
        mainPanel.setLayout(new BorderLayout());
        
        // 顶部时间显示
        JPanel topPanel = new JPanel(new BorderLayout());
        topPanel.add(new JLabel("9:41"), BorderLayout.WEST);
        mainPanel.add(topPanel, BorderLayout.NORTH);
        
        // 标题和编辑按钮
        JPanel titlePanel = new JPanel(new BorderLayout());
        titlePanel.add(new JLabel("购物车"), BorderLayout.WEST);
        JButton editButton = new JButton("编辑");
        titlePanel.add(editButton, BorderLayout.EAST);
        mainPanel.add(titlePanel, BorderLayout.CENTER);
        
        // 空购物车提示
        JPanel emptyCartPanel = new JPanel(new BorderLayout());
        emptyCartPanel.add(new JLabel("挑点喜欢的装进购物车吧", JLabel.CENTER), BorderLayout.CENTER);
        JButton browseButton = new JButton("去逛逛");
        emptyCartPanel.add(browseButton, BorderLayout.SOUTH);
        
        // 底部结算栏
        JPanel bottomPanel = new JPanel(new BorderLayout());
        JCheckBox selectAll = new JCheckBox("全选");
        bottomPanel.add(selectAll, BorderLayout.WEST);
        bottomPanel.add(new JLabel("合计：¥0.00"), BorderLayout.CENTER);
        JButton checkoutButton = new JButton("去结算(0)");
        bottomPanel.add(checkoutButton, BorderLayout.EAST);
        
        // 返回按钮
        JButton backButton = new JButton("返回主界面");
        JButton mySalesButton = new JButton("我卖的");
        
        // 组装主界面
        JPanel contentPanel = new JPanel();
        contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS));
        contentPanel.add(titlePanel);
        contentPanel.add(emptyCartPanel);
        contentPanel.add(bottomPanel);
        contentPanel.add(backButton);
        contentPanel.add(mySalesButton);
        
        mainPanel.add(contentPanel, BorderLayout.CENTER);
        add(mainPanel);
        
        // 添加按钮事件
        backButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new MainInterface().setVisible(true);
                dispose();
            }
        });
        
        mySalesButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                new MySalesInterface().setVisible(true);
                dispose();
            }
        });
    }
}